﻿Imports System.Data.OleDb

Public Class HoaDonDAO

    Public Function GetTable() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "select * from HOADON"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)

        cn.Close()
        Return dt
    End Function

    Public Function Insert(ByVal tmp As HoaDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into HOADON (MaBan, TongTien, ThoiGian, TinhTrangTT) values (@MaBan, @TongTien, @ThoiGian, @TinhTrangTT)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4 As OleDbParameter
        para1 = New OleDbParameter("@MaBan", tmp.MaBan)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@TongTien", tmp.TongTien)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@ThoiGian", tmp.ThoiGian)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@TinhTrang", tmp.TinhTrangTT)
        cmd.Parameters.Add(para4)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As HoaDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update HOADON set MaBan=@MaBan, TongTien=@TongTien, ThoiGian=@ThoiGian, TinhTrangTT=@TinhTrangTT where MaHD=@MaHD"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5 As OleDbParameter
        para1 = New OleDbParameter("@MaBan", tmp.MaBan)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@TongTien", tmp.TongTien)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@ThoiGian", tmp.ThoiGian)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@TinhTrangTT", tmp.TinhTrangTT)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@MaHD", tmp.MaHD)
        cmd.Parameters.Add(para5)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As HoaDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from HOADON where MaHD=@MaHD"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaHD", tmp.MaHD)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

End Class
